﻿@model FamaWebSite.Models.ParametrosModel

@{
    ViewBag.Title = "Execute";
}

<span style="float: left; font-weight: bold; font-size: medium; margin-right: 10px;">ALGORITMO:</span>
<span style="float: left; font-weight: bold; font-size: medium">@Model.Algoritmo</span>

<div id="tabs" style="margin-top: 20px">
    <ul>
        <li><a href="#tabs-1">Classificar</a></li>
        <li><a href="#tabs-2">Validar treino</a></li>
        <li><a href="#tabs-3">Validar teste</a></li>
        <li><a href="#tabs-4">Validar dobras</a></li>
        <li><a href="#tabs-5">Validar divisão</a></li>
    </ul>
    <div id="tabs-1">
        @Html.Partial("Classificar", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("ValidarTreino", Model)
    </div>
    <div id="tabs-3">
        @Html.Partial("ValidarTeste", Model)
    </div>
    <div id="tabs-4">
        @Html.Partial("ValidarDobras", Model)
    </div>
    <div id="tabs-5">
        @Html.Partial("ValidarDivisao", Model)
    </div>

    <div style="position: absolute; right: 200px; top: 60px;">
        <div class="editor-label">
            @Html.LabelFor(model => model.Resposta)
        </div>
        <div class="editor-field" style="border: 1px solid; margin-top: 10px; padding: 0 15px; background: #EFEFEF;">
            &nbsp;
        @if (Model.Resposta != null && Model.Resposta.Any())
        {
            foreach (var resposta in Model.Resposta)
            {
            <span>@String.Format("{0}%", resposta)</span>
            <br />
            }
        }
        </div>
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/jquerycookie")
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#tabs a").click(function () {
            var clickedTab = $(this).attr("href");
            $.cookie("CurrentTab", clickedTab);
        });


        $("#tabs").tabs();

        var currentTab = $.cookie("CurrentTab");
        if (currentTab != null) {
            $("#tabs a[href=" + currentTab + "]").click();
        }

        $(".actionlnkUpload").click(function (event) {
            event.preventDefault();

            $.ajax({
                url: "@Url.Action("Index", "Upload")",
                type: 'get',
            }).done(function (data) {
                $.colorbox({ open: true, html: data });
            });
        });

        $("#uploadFile").live('click', function (event) {
            event.preventDefault();

            var uploadFile = $("#inputFile").val();

            if (uploadFile) {
                var file = document.getElementById('inputFile').files[0];
                var formData = new FormData();
                formData.append(file.name, file);

                var xhr = new XMLHttpRequest();
                var url = $("#form-uploadFile").attr("action");
                xhr.open('POST', url, true);
                xhr.onload = function (e) {
                    $.colorbox.close();
                    var response = $.parseJSON(e.target.response);
                    if (response != null && response.Success)
                        $("#arquivoInputTreino, #arquivoInputTeste").append('<option>' + response.Filename + '</option>');
                    else
                        $('#msgErrorUploadFile').text(response.Message).show();
                };

                xhr.send(formData);  // multipart/form-data
            }
        });
    });
</script>
